package com.atguigu.gulimall.product.excelUtils;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Auther zhaolei
 * @Date 2022-06-07 下午10:23
 */

@RestController
@RequestMapping("product/poi")
public class ExcelPoiDemo {

    @RequestMapping("/export")
    public void pubggupload(@RequestParam("file") MultipartFile file) throws Exception {
        String name = file.getOriginalFilename();
        if(name.length() < 4 || !name.substring(name.length() - 4).equals(".xls")) {
            throw new Exception("文件格式错误");
        }
        // 获取Excel中的数据
        List<Detailed> detaileds = ExcelUtils.excelToShopIdList(file.getInputStream());
        // 向数据库遍历添加数据库
        for (int i = 0; i < detaileds.size(); i++) {
            // 获取行信息
           //Detailed detailed = detaileds.get(i);
           //// 先根据eneityid查询数据库里有没有一样的，没有就进行添加
           //List<Long> longs = readService.queryDetailedByEneityid(detailed.getEntityid());
           //if (longs.size() <= 0) {
           //    readService.addDetailed(detailed);
           //} else {
           //    System.out.println("error：该条信息已存在 message：" + detailed);
           //}
        }
    }
}
